import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** crm发票管理信息 */
export interface Receipt {
  id: number // ID
  code: string // 发票编号
  customerId: number // 客户id
  customerName: string // 客户名称
  contractId: number // 合同id
  contractCode: string // 合同编号
  receiptAmount: number // 开票金额
  receiptDate: string | Dayjs // 开票日期
  receiptType: boolean // 开票类型
  content: string // 开票内容
  titleId: number // 发票抬头id
  status: string // 开票状态
  processInstanceId: string // 工作流编号
  auditStatus: number // 审核状态
  remark: string // 备注
  ownerUserId: number // 负责人的用户编号
}

// crm发票管理 API
export const ReceiptApi = {
  // 查询crm发票管理分页
  getReceiptPage: async (params: any) => {
    return await request.get({ url: `/crm/receipt/page`, params })
  },

  // 查询crm发票管理详情
  getReceipt: async (id: number) => {
    return await request.get({ url: `/crm/receipt/get?id=` + id })
  },

  // 新增crm发票管理
  createReceipt: async (data: Receipt) => {
    return await request.post({ url: `/crm/receipt/create`, data })
  },

  // 修改crm发票管理
  updateReceipt: async (data: Receipt) => {
    return await request.put({ url: `/crm/receipt/update`, data })
  },

  // 删除crm发票管理
  deleteReceipt: async (id: number) => {
    return await request.delete({ url: `/crm/receipt/delete?id=` + id })
  },

  /** 批量删除crm发票管理 */
  deleteReceiptList: async (ids: number[]) => {
    return await request.delete({ url: `/crm/receipt/delete-list?ids=${ids.join(',')}` })
  },

  // 导出crm发票管理 Excel
  exportReceipt: async (params) => {
    return await request.download({ url: `/crm/receipt/export-excel`, params })
  },

  // 提交审核
  submitReceipt: async (id: number) => {
    return await request.put({ url: `/crm/receipt/submit?id=${id}` })
  }
}
